package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.InventoryManagement.AgentiaBean;
import com.project.mapper.IAgentiaMapper;
import com.project.service.IAgentiaService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class IAgentiaServiceImpl extends ServiceImpl<IAgentiaMapper, AgentiaBean> implements IAgentiaService {


    @Override
    public IPage<AgentiaBean> findCutAgentia(int pageNo, int pageSize, String agentiaName, String agentiaType, String agentiaCategory) {
       IPage<AgentiaBean> page = new Page<>(pageNo,pageSize);

        QueryWrapper wrapper = new QueryWrapper<>();

        if (agentiaName != null){
            wrapper.like("agentia_name",agentiaName);
        }
        if (agentiaType != null){
            wrapper.like("agentia_type",agentiaType);
        }
        if (agentiaCategory != null){
            wrapper.like("agentia_category",agentiaCategory);
        }

        IPage<AgentiaBean> iPage = this.baseMapper.selectPage(page,wrapper);

        return iPage;
    }

    @Override
    public void addAgentia(AgentiaBean agentiaBean) {

        this.baseMapper.insert(agentiaBean);

    }
}
